<template>
  <el-dialog
    width="400px"
    :visible.sync="visible"
    title="DHCP配置"
    :before-close="close"
    :close-on-click-modal="false"
  >
    <el-form class="form" ref="form" :model="form" label-width="100px">
      <el-form-item label="网络地址">
        <el-input size="mini" v-model="form.ip"></el-input>
      </el-form-item>
      <el-form-item label="子网掩码">
        <el-input size="mini" v-model="form.net_mask"></el-input>
      </el-form-item>
      <el-form-item label="开始地址">
        <el-input size="mini" v-model="form.start_ip"></el-input>
      </el-form-item>
      <el-form-item label="结束地址">
        <el-input size="mini" v-model="form.end_ip"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" type="primary" @click="onBindIp"
          >IP绑定</el-button
        >
        <el-button
          size="mini"
          type="primary"
          @click="onSave"
          v-loading.fullscreen.lock="fullscreenLoading"
          >保存</el-button
        >
        <el-button size="mini" @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
    <BindIpDialog ref="BindIpDialog"></BindIpDialog>
  </el-dialog>
</template>

<script>
// import { Loading } from "element-ui";
import BindIpDialog from "./BindIpDialog.vue";
export default {
  name: "EditDhcpDialog",
  components: {
    BindIpDialog,
  },
  data() {
    return {
      department: [],
      form: {
        ip: "",
        net_mask: "",
        start_ip: "",
        end_ip: "",
        count: 0,
        host: [
          {
            name: "test",
            ip: "192.168.88.88",
          },
          {
            name: "test2",
            ip: "192.168.88.82",
          },
        ],
      },
      fullscreenLoading: false,
      visible: false,
      isAdd: false, // 是否为添加
    };
  },
  created() {},
  mounted() {},
  methods: {
    open() {
      this.form = {};
      this.getDhcp();
      this.visible = true;
    },
    close() {
      this.visible = false;
      this.$emit("close");
    },
    getDhcp() {
      this.$fetch("/machine/dhcp").then((res) => {
        if (res.error == 0) {
          this.form = res.data;
        }
      });
    },
    onSave() {
      let obj = this.form;
      this.fullscreenLoading = true;
      this.$put("/machine/dhcp", obj).then((res) => {
        if (res.error == 0) {
          this.$message({
            message: "DHCP修改成功",
            type: "success",
          });
          this.close();
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
        this.fullscreenLoading = false;
        this.$emit("closeDialog");
      });
    },
    onCancel() {
      this.close();
    },
    onBindIp() {
      this.$refs.BindIpDialog.open(this.form);
    },
  },
};
</script>

<style scoped lang="scss">
.form {
  width: 300px;
  margin: 10px;
  .el-input,
  .el-select,
  .el-input-number {
    width: 200px;
  }
}
.foot {
  overflow: hidden;
  .el-button {
    margin: 10px;
    float: right;
  }
}
</style>


